import store from "./index"
import axios from "axios"

export const CHANGE_INPUT_VALUE = "CHANGE_INPUT_VALUE"
export const ADD_ITEM = "ADD_ITEM"
export const DELETE_TODO_ITEM = "DELETE_TODO_ITEM"
export const INI_LIST = "INI_LIST"
export const GET_INIT_LIST = "GET_INIT_LIST"

export const getInputValueAction = value => ({
  type: CHANGE_INPUT_VALUE,
  value
})

export const getDeleteItemAction = index => ({
  type: DELETE_TODO_ITEM,
  index
})

export const getAddItemAction = () => ({
  type: ADD_ITEM
})

export const getIniListAction = list => ({
  type: INI_LIST,
  list
})

export const getInitListActionWithSaga = (list) => ({
  type: GET_INIT_LIST,
  list
})

export const getInitListWithThunk = () => {
  return (dispatch) => {
      axios.get('/api/todolist.json').then( res =>{
      const data = res.data
      dispatch(getIniListAction(data))
    })
  }
  // setTimeout(() => {
  //   axios.get("/api/todolist.json").then(res => {
  //     store.dispatch(getIniListAction(res.data))
  //   })
  // }, 1000)
}
